package org.lai.service.impl;

import org.lai.mapper.EmpMapper;
import org.lai.mapper.StudentMapper;
import org.lai.pojo.ClazzsStudentCountOption;
import org.lai.pojo.jobOption;
import org.lai.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public jobOption getEmpJobData() {
        // 1. 调用mapper接口获取数据
        List<Map<String, Object>> list = empMapper.countEmpJobData(); // map: pos=教研主管,num=1
        // 2. 组装结果,并返回
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList(); //
        List<Object> numList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new jobOption(jobList,numList);

    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    /**
     * 统计班级人数
     *
     * @return
     */
    @Override
    public ClazzsStudentCountOption getStudentCountData() {
        // 数据封装
        List<Map<String, Object>> list = studentMapper.getStudentCountData();
        List<Object> clazzlist = list.stream().map(dataMap ->dataMap.get("clazzList")).toList();
        List<Object> numList = list.stream().map(dataMap -> dataMap.get("dataList")).toList();
        return new ClazzsStudentCountOption(clazzlist, numList);
    }

    /**
     * 统计学员学历
     * @return
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        List<Map<String, Object>> list = studentMapper.getStudentDegreeData();
        return list;
    }
}
